<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
     <!-- <el-form-item label="商标名称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入商标名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="企业名称" prop="companyname">
        <el-input
          v-model="queryParams.companyname"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农药名称" prop="pesticidename">
        <el-input
          v-model="queryParams.pesticidename"
          placeholder="请输入农药名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农药登记号" prop="pesticideregistrationnumber">
        <el-input
          v-model="queryParams.pesticideregistrationnumber"
          placeholder="请输入农药登记号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="毒性分级" prop="toxicitygrade">
        <el-input
          v-model="queryParams.toxicitygrade"
          placeholder="请输入毒性分级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="剂型" prop="drug">
        <el-input
          v-model="queryParams.drug"
          placeholder="请输入剂型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    <!--  <el-form-item label="农药状态" prop="pesticidestate">
        <el-input
          v-model="queryParams.pesticidestate"
          placeholder="请输入农药状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wuyi:nongyao:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wuyi:nongyao:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wuyi:nongyao:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wuyi:nongyao:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="nongyaoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="商标名称" align="center" prop="title" />-->
      <el-table-column label="企业名称" align="center" prop="companyname" />
      <el-table-column label="农药名称" align="center" prop="pesticidename" />
<!--      <el-table-column label="有效成分" align="center" prop="activeingredient" />-->
      <el-table-column label="含量" align="center" prop="content" />
<!--      <el-table-column label="农药登记情况" align="center" prop="pesticideregistration" />-->
      <el-table-column label="农药登记号" align="center" prop="pesticideregistrationnumber" />
<!--      <el-table-column label="登记有效期" align="center" prop="registrationvalidity" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.registrationvalidity, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="毒性分级" align="center" prop="toxicitygrade" />-->
      <el-table-column label="农药类型" align="center" prop="pesticidetype" />
      <el-table-column label="剂型" align="center" prop="drug" />
<!--      <el-table-column label="来源" align="center" prop="source" />-->
<!--      <el-table-column label="有效期" align="center" prop="date" />-->
<!--      <el-table-column label="1:限制使用农药 ；0：其他状态" align="center" prop="flag" />
      <el-table-column label="入库时间" align="center" prop="intime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.intime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="识别代码" align="center" prop="identifycode" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="净含量" align="center" prop="netcontent" />
      <el-table-column label="检验结果" align="center" prop="inspectionresult" />
      <el-table-column label="产品批号" align="center" prop="productnumber" />
      <el-table-column label="生产日期" align="center" prop="produceddate" />
      <el-table-column label="保质期" align="center" prop="expirationdate" />
      <el-table-column label="1表示人工添加，0表示采集数据" align="center" prop="biaoji" />
      <el-table-column label="加工批次" align="center" prop="jiagongnum" />
      <el-table-column label="查询次数" align="center" prop="selectnum" />
      <el-table-column label="规格" align="center" prop="guige" />
      <el-table-column label="生产许可证" align="center" prop="shengchanno" />
      <el-table-column label="生产地址" align="center" prop="addr" />
      <el-table-column label="产品标准号" align="center" prop="productstand" />
      <el-table-column label="生产线" align="center" prop="shengchanxian" />
      <el-table-column label="质检员" align="center" prop="zhijian" />
      <el-table-column label="产品识别码" align="center" prop="pin" />
      <el-table-column label="生产商" align="center" prop="shengchanperson" />
      <el-table-column label="追溯地址" align="center" prop="url" />
      <el-table-column label="农药状态" align="center" prop="pesticidestate" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wuyi:nongyao:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wuyi:nongyao:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改农药信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商标名称" prop="title">
          <el-input v-model="form.title" placeholder="请输入商标名称" />
        </el-form-item>
        <el-form-item label="企业名称" prop="companyname">
          <el-input v-model="form.companyname" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="农药名称" prop="pesticidename">
          <el-input v-model="form.pesticidename" placeholder="请输入农药名称" />
        </el-form-item>
        <el-form-item label="有效成分" prop="activeingredient">
          <el-input v-model="form.activeingredient" placeholder="请输入有效成分" />
        </el-form-item>
        <el-form-item label="含量">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="农药登记情况" prop="pesticideregistration">
          <el-input v-model="form.pesticideregistration" placeholder="请输入农药登记情况" />
        </el-form-item>
        <el-form-item label="农药登记号" prop="pesticideregistrationnumber">
          <el-input v-model="form.pesticideregistrationnumber" placeholder="请输入农药登记号" />
        </el-form-item>
        <el-form-item label="登记有效期" prop="registrationvalidity">
          <el-date-picker clearable
            v-model="form.registrationvalidity"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择登记有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="毒性分级" prop="toxicitygrade">
          <el-input v-model="form.toxicitygrade" placeholder="请输入毒性分级" />
        </el-form-item>
        <el-form-item label="剂型" prop="drug">
          <el-input v-model="form.drug" placeholder="请输入剂型" />
        </el-form-item>
        <el-form-item label="来源" prop="source">
          <el-input v-model="form.source" placeholder="请输入来源" />
        </el-form-item>
        <el-form-item label="有效期" prop="date">
          <el-input v-model="form.date" placeholder="请输入有效期" />
        </el-form-item>
        <el-form-item label="1:限制使用农药 ；0：其他状态" prop="flag">
          <el-input v-model="form.flag" placeholder="请输入1:限制使用农药 ；0：其他状态" />
        </el-form-item>
        <el-form-item label="入库时间" prop="intime">
          <el-date-picker clearable
            v-model="form.intime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入库时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="识别代码" prop="identifycode">
          <el-input v-model="form.identifycode" placeholder="请输入识别代码" />
        </el-form-item>
        <el-form-item label="净含量">
          <editor v-model="form.netcontent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="检验结果" prop="inspectionresult">
          <el-input v-model="form.inspectionresult" placeholder="请输入检验结果" />
        </el-form-item>
        <el-form-item label="产品批号" prop="productnumber">
          <el-input v-model="form.productnumber" placeholder="请输入产品批号" />
        </el-form-item>
        <el-form-item label="生产日期" prop="produceddate">
          <el-input v-model="form.produceddate" placeholder="请输入生产日期" />
        </el-form-item>
        <el-form-item label="保质期" prop="expirationdate">
          <el-input v-model="form.expirationdate" placeholder="请输入保质期" />
        </el-form-item>
        <el-form-item label="1表示人工添加，0表示采集数据" prop="biaoji">
          <el-input v-model="form.biaoji" placeholder="请输入1表示人工添加，0表示采集数据" />
        </el-form-item>
        <el-form-item label="加工批次" prop="jiagongnum">
          <el-input v-model="form.jiagongnum" placeholder="请输入加工批次" />
        </el-form-item>
        <el-form-item label="查询次数" prop="selectnum">
          <el-input v-model="form.selectnum" placeholder="请输入查询次数" />
        </el-form-item>
        <el-form-item label="规格" prop="guige">
          <el-input v-model="form.guige" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="生产许可证" prop="shengchanno">
          <el-input v-model="form.shengchanno" placeholder="请输入生产许可证" />
        </el-form-item>
        <el-form-item label="生产地址" prop="addr">
          <el-input v-model="form.addr" placeholder="请输入生产地址" />
        </el-form-item>
        <el-form-item label="产品标准号" prop="productstand">
          <el-input v-model="form.productstand" placeholder="请输入产品标准号" />
        </el-form-item>
        <el-form-item label="生产线" prop="shengchanxian">
          <el-input v-model="form.shengchanxian" placeholder="请输入生产线" />
        </el-form-item>
        <el-form-item label="质检员" prop="zhijian">
          <el-input v-model="form.zhijian" placeholder="请输入质检员" />
        </el-form-item>
        <el-form-item label="产品识别码" prop="pin">
          <el-input v-model="form.pin" placeholder="请输入产品识别码" />
        </el-form-item>
        <el-form-item label="生产商" prop="shengchanperson">
          <el-input v-model="form.shengchanperson" placeholder="请输入生产商" />
        </el-form-item>
        <el-form-item label="追溯地址" prop="url">
          <el-input v-model="form.url" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="农药状态" prop="pesticidestate">
          <el-input v-model="form.pesticidestate" placeholder="请输入农药状态" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="updateDate">
          <el-date-picker clearable
            v-model="form.updateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="删除标识" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNongyao, getNongyao, delNongyao, addNongyao, updateNongyao } from "@/api/wuyi/nongyao";

export default {
  name: "Nongyao",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 农药信息表格数据
      nongyaoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        companyname: null,
        pesticidename: null,
        activeingredient: null,
        content: null,
        pesticideregistration: null,
        pesticideregistrationnumber: null,
        registrationvalidity: null,
        toxicitygrade: null,
        pesticidetype: null,
        drug: null,
        source: null,
        date: null,
        flag: null,
        intime: null,
        identifycode: null,
        status: null,
        netcontent: null,
        inspectionresult: null,
        productnumber: null,
        produceddate: null,
        expirationdate: null,
        biaoji: null,
        jiagongnum: null,
        selectnum: null,
        guige: null,
        shengchanno: null,
        addr: null,
        productstand: null,
        shengchanxian: null,
        zhijian: null,
        pin: null,
        shengchanperson: null,
        url: null,
        pesticidestate: null,
        createDate: null,
        updateDate: null,
        remarks: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        delFlag: [
          { required: true, message: "删除标识不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询农药信息列表 */
    getList() {
      this.loading = true;
      listNongyao(this.queryParams).then(response => {
        this.nongyaoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        companyname: null,
        pesticidename: null,
        activeingredient: null,
        content: null,
        pesticideregistration: null,
        pesticideregistrationnumber: null,
        registrationvalidity: null,
        toxicitygrade: null,
        pesticidetype: null,
        drug: null,
        source: null,
        date: null,
        flag: null,
        intime: null,
        identifycode: null,
        status: "0",
        netcontent: null,
        inspectionresult: null,
        productnumber: null,
        produceddate: null,
        expirationdate: null,
        biaoji: null,
        jiagongnum: null,
        selectnum: null,
        guige: null,
        shengchanno: null,
        addr: null,
        productstand: null,
        shengchanxian: null,
        zhijian: null,
        pin: null,
        shengchanperson: null,
        url: null,
        pesticidestate: null,
        createBy: null,
        createDate: null,
        updateBy: null,
        updateDate: null,
        remarks: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加农药信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNongyao(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改农药信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNongyao(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNongyao(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除农药信息编号为"' + ids + '"的数据项？').then(function() {
        return delNongyao(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuyi/nongyao/export', {
        ...this.queryParams
      }, `nongyao_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
